<template>
  <!-- 智能催收-短信催收 -->
  <section class="page message-collection">
    
    <data-form :model="model" @onSearch="refreshData" :page="pageService">
      <template slot="inputs">
        <el-form-item label="借据号" prop="caseNumber">
          <el-input v-model.trim="model.caseNumber"></el-input>
        </el-form-item>
        <el-form-item label="客户姓名" prop="personalName">
          <el-input v-model.trim="model.personalName"></el-input>
        </el-form-item>
        <el-form-item label="当前催收员" prop="currentCollectorRealName">
          <el-input v-model.trim="model.currentCollectorRealName"></el-input>
        </el-form-item>
        <el-form-item label="逾期阶段" prop="overduePeriod">
          <el-select v-model="model.overduePeriod" placeholder="请选择" clearable>
            <el-option v-for="{index,name,code} in $dict.getDictData('OverduePeriodStatus')" :key="index" :label="name" :value="code.replace(/M|\+/, '')"></el-option>
          </el-select>
        </el-form-item>
      </template>
    </data-form>

    <data-box :data="dataSet" :selectionList.sync="selectionList" @onPageChange="refreshData" :sort="sortService" :page="pageService">
      <template slot="buttons">
        <el-button @click="batchMessage" v-auth = "2210">短信群发</el-button>
      </template>
      <template slot="columns">
        <el-table-column prop="caseNumber" label="借据号" :min-width="$helper.getColumnWidth(6)">
        </el-table-column>
        <el-table-column prop="personalName" label="客户姓名" :min-width="$helper.getColumnWidth(3)">
        </el-table-column>
        <el-table-column prop="mobileNo" label="手机号" :formatter="(row)=>$filter.encryptPhone(row.mobileNo)" :min-width="$helper.getColumnWidth(4)">
        </el-table-column>
        <el-table-column prop="overdueAmount" label="案件金额(元)" :min-width="$helper.getColumnWidth(4)">
        </el-table-column>
        <el-table-column prop="overduePeriod" label="逾期阶段" :min-width="$helper.getColumnWidth(3)">
        </el-table-column>
        <el-table-column prop="overdueDays" label="逾期天数" :min-width="$helper.getColumnWidth(3)">
        </el-table-column>
        <el-table-column prop="currentCollector" label="永久催收员" :min-width="$helper.getColumnWidth(4)">
        </el-table-column>
        <el-table-column prop="followinTime" label="案件流入时间" :formatter="(row) => $filter.dateTimeFormat(row.followinTime)" :min-width="$helper.getColumnWidth(5)">
        </el-table-column>
      </template>
    </data-box>

    <!--批量发送短信-->
    <el-dialog :visible="visiable" :show-close="false" :close-on-click-modal="false" :close-on-press-escape="false">
      <message-send-relation></message-send-relation>
    </el-dialog>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Auth, Layout, Dependencies } from "~/core/decorator";
import { State, namespace } from "vuex-class";
import { PageService } from "~/utils/page.service";
import { SortService } from "~/utils/sort.service";
import DataForm from "~/components/common/data-form.vue";
import DataBox from "~/components/common/data-box.vue";
import MessageSendRelation from '~/components/smart-collection/message-collection/message-send-relation.vue';
import { SmartCollectionService } from "~/services/domain-service/smart-collection.service";

const MessageCollectionModule = namespace('message-collection')

@Layout("workspace")
@Component({
  components: {
    DataForm,
    DataBox,
    MessageSendRelation,
  }
})
export default class MessageCollection extends Vue {
  @Dependencies(PageService)
  private pageService: PageService
  @Dependencies(SortService)
  private sortService: SortService
  @Dependencies(SmartCollectionService)
  private smartCollectionService: SmartCollectionService
  @MessageCollectionModule.State
  private relationState: boolean
  @MessageCollectionModule.Action
  private updateCaseIdList
  @MessageCollectionModule.Action
  private updateRelationState

  private dataSet: any[] = []
  private selectionList: any[] = []

  private model: any = {
    caseNumber: '',
    personalName: '',
    currentCollectorRealName: '',
  }

  private get visiable() {
    return this.relationState
  }

  private batchMessage() {
    if (this.selectionList.length === 0) {
      this.$message.warning('请先选择案件')
      return
    }
    const caseIdList: any[] = this.selectionList.map(v => v.id)
    this.updateCaseIdList(caseIdList)
    this.updateRelationState(true)
  }

  private refreshData() {
      this.smartCollectionService.getAllCollectionCaseInfo(this.model, this.pageService)
      .subscribe((data) => {
        this.dataSet = data
        if(this.dataSet){
          this.dataSet.forEach(x=>{
            x.overduePeriod>12?x.overduePeriod = 'M12+':x.overduePeriod = 'M'+x.overduePeriod
          })
        }
      });
  }

  private mounted() {
    this.refreshData()
  }

}
</script>

<style lang="less" scoped>
</style>
